import type { ApiResult, PageParam, PageResult } from '~/types/global'
import type { Config } from '~/types/system/config'
import { request } from '~/utils/request'
import type { SysDictItem } from '~/types/system/dictItem'

enum Api {
  Page = '/system/config/page',
  Query = '/system/role/query',
  AddConfig = '/system/config',
  Batch = '/system/config/batch',
  getDictItem = '/system/dictItem/codeList',
}

/**
 * 分页查询
 * @return
 */
export function pageConfigApi(param: PageParam<Config>) {
  return request.post<ApiResult<PageResult<Config>>>(Api.Page, { data: param })
}

/**
 * 查询所有
 * @return
 */
export function queryRoleApi(param: SysRole = {}) {
  return request.post<ApiResult<SysRole[]>>(Api.Query, { data: param })
}

/**
 * 获取指定角色信息
 * @param id
 * @return
 */
export function getRoleApi(id: string) {
  // return request.get<ApiResult<SysRole>>(`${Api.Common}/${id}`)
}

/**
 * 新增
 * @param param
 * @return
 */
export function addConfigDictItemApi(param: Config) {
  return request.post<ApiResult<boolean>>(Api.AddConfig, { data: param })
}

/**
 * 修改
 * @param param
 * @return
 */
export function updateConfigApi(param: Config) {
  return request.put<ApiResult<boolean>>(Api.AddConfig, { data: param })
}

/**
 * 删除
 * @param id
 * @return
 */
export function deleteConfigApi(id: string) {
  return request.delete<ApiResult<boolean>>(`${Api.AddConfig}/${id}`)
}

/**
 * 批量删除
 * @param ids
 * @return
 */
export function batchDeleteConfigApi(ids: string[]) {
  return request.delete<ApiResult<boolean>>(Api.Batch, { data: ids })
}

/**
 * 根据code 查询字典项
 */
export function getConfigDictItemApi(code: string) {
  return request.post<ApiResult<SysDictItem[]>>(Api.getDictItem, { data: { code } })
}
